clear all
set more off
cap log close

ssc install unique
    
global dir "/Replication Archive"
cd "${dir}"

global outreg_settings = " label bdec(4) pvalue pdec(3) tex(frag) excel  nor2 nonotes "

	
*************************************
************* FIGURE 1 **************
*************************************

* Merge an additional variable needed
use "${dir}/Data/Final Datasets/Directors_Information.dta", clear
keep catorder_num catorder sector
duplicates drop catorder_num, force
tempfile temp
save "`temp'" , replace 
use "${dir}/Data/Final Datasets/Final_Data_Director_MC_Level_DEF2.dta", clear
merge m:1 catorder_num using  "`temp'"
drop _m

egen double Director_Company_MC=group(DirectorID CompanyID icpsr2 chamber)
egen double Director_MC=group(DirectorID icpsr2 chamber)
egen double Congress_MC=group(icpsr2 chamber cycle)
egen double Congress_Director_Company=group(DirectorID CompanyID cycle chamber)

gen donated=(amount_noself>0)
replace donated=donated*1000

gen relevant_agri=(relevant==1 & sector=="Agribusiness")
gen relevant_comm_elect=(relevant==1 & sector=="Communic/Electronics")
gen relevant_construction=(relevant==1 & sector=="Construction")
gen relevant_defense=(relevant==1 & sector=="Defense")
gen relevant_energy=(relevant==1 & sector=="Energy/Nat Resource")
gen relevant_finance_ins_re=(relevant==1 & sector=="Finance/Insur/RealEst")
gen relevant_health=(relevant==1 & sector=="Health")
gen relevant_lawyers=(relevant==1 & sector=="Lawyers & Lobbyists")
gen relevant_business=(relevant==1 & sector=="Misc Business")
gen relevant_other=(relevant==1 & sector=="Other")
gen relevant_transport=(relevant==1 & sector=="Transportation")

reghdfe donated relevant_agri relevant_comm_elect relevant_construction relevant_defense relevant_energy relevant_finance_ins_re relevant_health relevant_lawyers relevant_business relevant_other relevant_transport, absorb(Director_Company_MC Congress_MC Congress_Director_Company) cluster(Director_MC) compact keepsingletons
su donated if relevant ==0 & sector=="Agribusiness" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_agri = _b[relevant_agri]/`mean'*100
local effect_agri: display %5.4fc `effect_agri'
local ub_b_agri = (_b[relevant_agri] + 1.96*_se[relevant_agri])/`mean'*100
local lb_b_agri = (_b[relevant_agri] - 1.96*_se[relevant_agri])/`mean'*100
su donated if relevant ==0 & sector=="Communic/Electronics" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_comm_elect = _b[relevant_comm_elect]/`mean'*100
local effect_comm_elect: display %5.4fc `effect_comm_elect'
local ub_b_comm_elect = (_b[relevant_comm_elect] + 1.96*_se[relevant_comm_elect])/`mean'*100
local lb_b_comm_elect = (_b[relevant_comm_elect] - 1.96*_se[relevant_comm_elect])/`mean'*100
su donated if relevant ==0 & sector=="Construction" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_construction = _b[relevant_construction]/`mean'*100
local effect_construction: display %5.4fc `effect_construction'
local ub_b_construction = (_b[relevant_construction] + 1.96*_se[relevant_construction])/`mean'*100
local lb_b_construction = (_b[relevant_construction] - 1.96*_se[relevant_construction])/`mean'*100
su donated if relevant ==0 & sector=="Defense" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_defense = _b[relevant_defense]/`mean'*100
local effect_defense: display %5.4fc `effect_defense'
local ub_b_defense = (_b[relevant_defense] + 1.96*_se[relevant_defense])/`mean'*100
local lb_b_defense = (_b[relevant_defense] - 1.96*_se[relevant_defense])/`mean'*100
su donated if relevant ==0 & sector=="Energy/Nat Resource" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_energy = _b[relevant_energy]/`mean'*100
local effect_energy: display %5.4fc `effect_energy'
local ub_b_energy = (_b[relevant_energy] + 1.96*_se[relevant_energy])/`mean'*100
local lb_b_energy = (_b[relevant_energy] - 1.96*_se[relevant_energy])/`mean'*100
su donated if relevant ==0 & sector=="Finance/Insur/RealEst" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_finance_ins_re = _b[relevant_finance_ins_re]/`mean'*100
local effect_finance_ins_re: display %5.4fc `effect_finance_ins_re'
local ub_b_finance_ins_re = (_b[relevant_finance_ins_re] + 1.96*_se[relevant_finance_ins_re])/`mean'*100
local lb_b_finance_ins_re = (_b[relevant_finance_ins_re] - 1.96*_se[relevant_finance_ins_re])/`mean'*100
su donated if relevant ==0 & sector=="Health" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_health = _b[relevant_health]/`mean'*100
local effect_health: display %5.4fc `effect_health'
local ub_b_health = (_b[relevant_health] + 1.96*_se[relevant_health])/`mean'*100
local lb_b_health = (_b[relevant_health] - 1.96*_se[relevant_health])/`mean'*100
su donated if relevant ==0 & sector=="Lawyers & Lobbyists" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_lawyers = _b[relevant_lawyers]/`mean'*100
local effect_lawyers: display %5.4fc `effect_lawyers'
local ub_b_lawyers = (_b[relevant_lawyers] + 1.96*_se[relevant_lawyers])/`mean'*100
local lb_b_lawyers = (_b[relevant_lawyers] - 1.96*_se[relevant_lawyers])/`mean'*100
su donated if relevant ==0 & sector=="Misc Business" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_business = _b[relevant_business]/`mean'*100
local effect_business: display %5.4fc `effect_business'
local ub_b_business = (_b[relevant_business] + 1.96*_se[relevant_business])/`mean'*100
local lb_b_business = (_b[relevant_business] - 1.96*_se[relevant_business])/`mean'*100
su donated if relevant ==0 & sector=="Other" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_other = _b[relevant_other]/`mean'*100
local effect_other: display %5.4fc `effect_other'
local ub_b_other = (_b[relevant_other] + 1.96*_se[relevant_other])/`mean'*100
local lb_b_other = (_b[relevant_other] - 1.96*_se[relevant_other])/`mean'*100
su donated if relevant ==0 & sector=="Transportation" & e(sample)==1, d
local mean: display %5.4fc `r(mean)' 
local effect_transport = _b[relevant_transport]/`mean'*100
local effect_transport: display %5.4fc `effect_transport'
local ub_b_transport = (_b[relevant_transport] + 1.96*_se[relevant_transport])/`mean'*100
local lb_b_transport = (_b[relevant_transport] - 1.96*_se[relevant_transport])/`mean'*100

* Reshape dataset
clear
set obs 11
gen sector_d=_n
gen n=_n
gen perc=.
replace perc=`effect_energy' if n==1
replace perc=`effect_lawyers' if n==2
replace perc=`effect_agri' if n==3
replace perc=`effect_construction' if n==4
replace perc=`effect_transport' if n==5
replace perc=`effect_other' if n==6
replace perc=`effect_business' if n==7
replace perc=`effect_comm_elect' if n==8
replace perc=`effect_health' if n==9
replace perc=`effect_finance_ins_re' if n==10
replace perc=`effect_defense' if n==11
gen perclb=.
replace perclb=`lb_b_energy' if n==1
replace perclb=`lb_b_lawyers' if n==2
replace perclb=`lb_b_agri' if n==3
replace perclb=`lb_b_construction' if n==4
replace perclb=`lb_b_transport' if n==5
replace perclb=`lb_b_other' if n==6
replace perclb=`lb_b_business' if n==7
replace perclb=`lb_b_comm_elect' if n==8
replace perclb=`lb_b_health' if n==9
replace perclb=`lb_b_finance_ins_re' if n==10
replace perclb=`lb_b_defense' if n==11
gen percub=.
replace percub=`ub_b_energy' if n==1
replace percub=`ub_b_lawyers' if n==2
replace percub=`ub_b_agri' if n==3
replace percub=`ub_b_construction' if n==4
replace percub=`ub_b_transport' if n==5
replace percub=`ub_b_other' if n==6
replace percub=`ub_b_business' if n==7
replace percub=`ub_b_comm_elect' if n==8
replace percub=`ub_b_health' if n==9
replace percub=`ub_b_finance_ins_re' if n==10
replace percub=`ub_b_defense' if n==11

gen label_var=""
forvalues i=1(1)11 {
su perc if n==`i'
local mean`i': display %5.0fc `r(mean)' 
replace label_var="`mean`i''%" if n==`i'
}


				twoway  (scatter sector_d perc, mcolor(gs3) lcolor(dkgrey) lpattern(solid) msymbol(D) mlabel(label_var) mlabposition(12) mlabgap(1.5) mlabs(small) mlabc(gs3)) ///
				(rcap perclb percub sector_d, hor lcolor(gs3) lpattern(solid)), ///
				xline(0, lpattern(dash) lcolor(gs6) ) ///
				graphregion(color(white)) plotregion(color(white)) ///
				xlabel(-20 "-20%" -10 "-10%" 0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%" 60 "60%" 70 "70%", labs(small)) ///
				ytitle("") ///
				ylabel(1 `" "Energy/Natural Resources"  "' 2 `" "Lawyers" "' 3 `" "Agribusiness" "' 4 `" "Construction" "' 5 `" "Transportation" "' ///
				6 `" "Education/Welfare" "' 7 `" "Miscellaneous Business" "' 8 `" "Communication/Electronics" "' 9 `" "Health" "' ///
				10 `" "Finance/Insurance/Real Estate" "' 11 `" "Defense" "', angle(horizontal) labs(small) nogrid) ///
				legend(off)	
				graph export "${dir}/Results/Figure_1.pdf", as(pdf) replace
				graph save "${dir}/Results/Figure_1", replace

	

log close

* Number of observations
use "${dir}/Data/Final Datasets/Directors_Information.dta", clear
bys sector: gen N=_N
su N if sector=="Agribusiness" 
su N if sector=="Communic/Electronics" 
su N if sector=="Construction" 
su N if sector=="Defense" 
su N if sector=="Energy/Nat Resource" 
su N if sector=="Finance/Insur/RealEst" 
su N if sector=="Health" 
su N if sector=="Lawyers & Lobbyists" 
su N if sector=="Misc Business" 
su N if sector=="Other" 
su N if sector=="Transportation"
